/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.hboxs.asl.util.DateUtils;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.CascadeType.REMOVE;

/**
 * Entity - 总分类
 */
@Entity
@Table(name = "xx_category")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_category_sequence")
public class Category extends OrderEntity {

    private static final long serialVersionUID = -5132652107151987662L;

    private String name;

    private String imageURL;

    private Set<Member> members = new HashSet<>();

    private Set<Course> courses = new HashSet<>();

    private Set<Essay> essays = new HashSet<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImageURL() {
        return imageURL;
    }

    public void setImageURL(String imageURL) {
        this.imageURL = imageURL;
    }

    @OneToMany(mappedBy = "category", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Member> getMembers() {
        return members;
    }

    public void setMembers(Set<Member> members) {
        this.members = members;
    }

    @OneToMany(mappedBy = "category", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Course> getCourses() {
        return courses;
    }

    public void setCourses(Set<Course> courses) {
        this.courses = courses;
    }

    @OneToMany(mappedBy = "category", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Essay> getEssays() {
        return essays;
    }

    public void setEssays(Set<Essay> essays) {
        this.essays = essays;
    }

    @Transient
    public String getCreateDateF(){
        return DateUtils.date2Str(super.getCreateDate());
    }
}